package org.penguin.study.bk.entity.r2dbc

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonInclude
import org.penguin.study.bk.annotation.NoArg
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
import java.io.Serializable
import java.time.LocalDateTime
import javax.validation.constraints.NotBlank

@NoArg
@Table("tbl_messages")
data class  Message(
    @Id
    var id: String? = null,

    @get: NotBlank
    var text: String?,
    var checked: Boolean? = null,
    var createdTime: LocalDateTime = LocalDateTime.now(),
    @JsonInclude(JsonInclude.Include.NON_NULL)
    var updatedTime: LocalDateTime? = null
) : Serializable {

    @JsonInclude(JsonInclude.Include.NON_NULL)
    var createdBy: String? = null

    var checkedText: String? = null
        get() = checked?.let { if (it) "已审批" else "被拒绝" } ?: "待审批"

    @JsonIgnore
    @Transient
    val checkToStringConverter: (Boolean?) -> String = { it?.let { if (it) "已审批" else "被拒绝" } ?: "待审批" }
}